package com.ruoyi.merchant.rabbitmq.listener;

import com.rabbitmq.client.Channel;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.merchant.api.OrderService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class OrderListener {
    @Autowired
    private RedisService redisService;
    @Autowired
    private OrderService orderService;

    @RabbitListener(queues = "order_normal_queue")
    public void listenerMessage(String message) {
        if (redisService.hasKey("order" + message)){
            orderService.ordertimeout(Long.parseLong(message),SecurityConstants.INNER);
            redisService.deleteObject("order" + message);
        }
    }
}
